package com.ruoyi.cms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cms.domain.CmsBannerItem;
import com.ruoyi.cms.service.ICmsBannerItemService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 广告Controller
 * 
 * @author he
 * @date 2025-06-23
 */
@RestController
@RequestMapping("/cms/item")
public class CmsBannerItemController extends BaseController
{
    @Autowired
    private ICmsBannerItemService cmsBannerItemService;

    /**
     * 查询广告列表
     */
    @PreAuthorize("@ss.hasPermi('cms:item:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmsBannerItem cmsBannerItem)
    {
        startPage();
        List<CmsBannerItem> list = cmsBannerItemService.selectCmsBannerItemList(cmsBannerItem);
        return getDataTable(list);
    }

    /**
     * 导出广告列表
     */
    @PreAuthorize("@ss.hasPermi('cms:item:export')")
    @Log(title = "广告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmsBannerItem cmsBannerItem)
    {
        List<CmsBannerItem> list = cmsBannerItemService.selectCmsBannerItemList(cmsBannerItem);
        ExcelUtil<CmsBannerItem> util = new ExcelUtil<CmsBannerItem>(CmsBannerItem.class);
        util.exportExcel(response, list, "广告数据");
    }

    /**
     * 获取广告详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:item:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cmsBannerItemService.selectCmsBannerItemById(id));
    }

    /**
     * 新增广告
     */
    @PreAuthorize("@ss.hasPermi('cms:item:add')")
    @Log(title = "广告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsBannerItem cmsBannerItem)
    {
        return toAjax(cmsBannerItemService.insertCmsBannerItem(cmsBannerItem));
    }

    /**
     * 修改广告
     */
    @PreAuthorize("@ss.hasPermi('cms:item:edit')")
    @Log(title = "广告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsBannerItem cmsBannerItem)
    {
        return toAjax(cmsBannerItemService.updateCmsBannerItem(cmsBannerItem));
    }

    /**
     * 删除广告
     */
    @PreAuthorize("@ss.hasPermi('cms:item:remove')")
    @Log(title = "广告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmsBannerItemService.deleteCmsBannerItemByIds(ids));
    }
}
